package com.baiyinet;

import com.alivc.player.AliVcMediaPlayer;
import com.baiyinet.di.Injector;
import com.baiyinet.di.module.AppModule;
import com.jude.utils.JUtils;
import com.mob.MobApplication;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.analytics.MobclickAgent;


import java.io.IOException;
import java.io.InputStream;

import javax.inject.Singleton;

import autodagger.AutoComponent;
import cn.jpush.android.api.JPushInterface;
import timber.log.Timber;

/**
 * @author J.Huang
 * @version 1.0
 * @since 16/11/8
 */

@AutoComponent(modules = AppModule.class)
@Singleton
public class MyApp extends MobApplication {

    @Override
    public void onCreate() {
        super.onCreate();

        if (BuildConfig.DEBUG) {
            Timber.plant(new Timber.DebugTree());
//            LeakCanary.install(this);
        }

        // 初始化极光推送
        JPushInterface.setDebugMode(BuildConfig.DEBUG);
        JPushInterface.init(this);

        // 初始化DI依赖注入框架Dagger2
        // 务必先初始化AppComponent
        Injector.initMyAppComponent(this);

        // 由于使用到了Fragment，禁止默认的只针对Activity的友盟页面统计方式
        MobclickAgent.openActivityDurationTrack(false);

        JUtils.initialize(this);

        IWXAPI wxApi = WXAPIFactory.createWXAPI(this, BuildConfig.WECHAT_APP_ID);
        wxApi.registerApp(BuildConfig.WECHAT_APP_ID);

        //初始化播放器（只需调用一次即可，建议在application中初始化）
        AliVcMediaPlayer.init(getApplicationContext());

//        TbsDownloader.needDownload(getApplicationContext(), false);
    }
}
